package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.entity.${className!""};
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.result.PageResult;
import com.zuipin.framework.result.Result;
import com.zuipin.service.I${className!""}Service;
import com.zuipin.util.Pagination;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * ${remark!""}Controller
 * 
 * @ClassName: ${className!""}Controller
 * @Description: TODO
 * @author ${author!"robot"}
 * @date ${.now?string("yyyy年MM月dd7日 HH:mm:ss")}
 */
@Api(value = "${remark!""}", description = "${remark!""}")
@RestController
@RequestMapping(value = "/${obName!""}")
public class  ${className!""}Controller {
	@Resource
	public I${className!""}Service ${obName!""}Service;

	
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	@ApiOperation(value = "根据主键查询${remark!""}", notes = "查询${remark!""}")
	public Result<${className!""}> get${className!""}By${PKName!""}(<#assign i=0 /><#list propertyEntityList as pro><#if pro.pkType=1><#if (i>0) >,</#if>@ApiParam(required = true, name = "${pro.propName}", value = "${pro.remarks!""}") @RequestParam ${pro.propType} ${pro.propName}<#assign i=i+1 /></#if></#list>){
		${className!""} ${obName!""} = ${obName!""}Service.findBy${PKName!""}(<#assign i=0 /><#list propertyEntityList as pro><#if pro.pkType=1><#if (i>0) >,</#if>${pro.propName}<#assign i=i+1 /></#if></#list>);
		Result<${className!""}> result = new Result<${className!""}>();
		if (${obName!""} != null) {
			result.setData(${obName!""});
			result.setErrorCode(ErrorCode.SUCCESS);
		} else {
			result.setErrorCode(ErrorCode.ELSE);
		}
		return result;
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ApiOperation(value = "新增${remark!""}", notes = "新增${remark!""}")
	@Valids({
	<#list propertyEntityList as pro>
		<#if pro.pkType=0>@Valid(name = "${obName!""}.${pro.propName!""}",  maxLength = ${pro.datasize!""}),</#if>
	</#list>		
	})
	@ApiImplicitParams({
	<#list propertyEntityList as pro>
		<#if pro.pkType=0>@ApiImplicitParam(name = "${obName!""}.${pro.propName!""}", value = "${pro.remarks!""}", <#if (pro.nullable)! = 0>required = true,</#if> dataType = "${pro.propLowType!""}", paramType = "query"),</#if>
	</#list>
	})
	public Result<${className!""}> insert${className!""}(@Inject @ApiIgnore ${className!""} ${obName!""}) {
		Result<${className!""}> result = new Result<${className!""}>();
		${obName!""}Service.insert(${obName!""});
		result.setData(${obName!""});
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ApiOperation(value = "根据主键修改${remark!""}", notes = "修改${remark!""}")
	@Valids({ 
	<#list propertyEntityList as pro>
		@Valid(name = "${obName!""}.${pro.propName!""}",  maxLength = ${pro.datasize!""}),
	</#list>	
	})
	@ApiImplicitParams({
	<#list propertyEntityList as pro>
		@ApiImplicitParam(name = "${obName!""}.${pro.propName!""}", value = "${pro.remarks!""}"<#if pro.nullable = 0 || pro.pkType=1 >, required = true</#if>, dataType = "${pro.propLowType!""}", paramType = "query"),
	</#list>
	})
	public Result<${className!""}> update${className!""}(@Inject @ApiIgnore ${className!""} ${obName!""}) {
		Result<${className!""}> result = new Result<${className!""}>();
		${obName!""}Service.update(${obName!""});
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/del", method = RequestMethod.DELETE)
	@ApiOperation(value = "根据主键删除${remark!""}", notes = "删除${remark!""}")
	public Result<${className!""}> del${className!""}(<#list propertyEntityList as pro><#if pro.pkType=1> ${pro.propType!""} ${pro.propName}</#if></#list>) {
		Result<${className!""}> result = new Result<${className!""}>();
		${obName!""}Service.delete(<#list propertyEntityList as pro><#if pro.pkType=1>${pro.propName}</#if></#list>);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/seach", method = RequestMethod.POST)
	@ApiOperation(value = "搜索${remark!""}SKU${remark!""}并分页", notes = "搜索${remark!""}并分页")
	@Valids({
	<#list propertyEntityList as pro>
		<#if pro.pkType=0>@Valid(name = "${obName!""}.${pro.propName!""}",  maxLength = ${pro.datasize!""}),</#if>
	</#list>	
		@Valid(name = "page.pageNumber",  maxValue = 999),
		@Valid(name = "page.pageSize",  maxValue = 999),
	})
	@ApiImplicitParams({
	<#list propertyEntityList as pro>
		<#if pro.pkType=0>@ApiImplicitParam(name = "${obName!""}.${pro.propName!""}", value = "${pro.remarks!""}"<#if pro.nullable = 0>, required = true</#if>, dataType = "${pro.propLowType!""}", paramType = "query"),</#if>
	</#list>
		@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
		@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"),
	})
	public Result<List<${className!""}>> seach${className!""}(@Inject @ApiIgnore ${className!""} ${obName!""},
			@Inject @ApiIgnore Pagination page) {
		PageResult<List<${className!""}>> result = new PageResult<List<${className!""}>>();
		result.setData(${obName!""}Service.seach${className!""}(${obName!""}, page));
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
